package com.snj.test2507;

public class MapStringProcessor {
    public static String processMapObject(Object mapObject) {
        if (mapObject == null) {
            return null;
        }
        String mapString = mapObject.toString();
        // 处理空映射的情况，直接返回 null
        if ("{}".equals(mapString)) {
            return null;
        }
        // 去除首尾的大括号
        String trimmed = mapString.substring(1, mapString.length() - 1);
        // 分割键值对
        String[] keyValuePairs = trimmed.split(", ");
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < keyValuePairs.length; i++) {
            // 处理每个键值对，将等号替换为连字符
            String[] parts = keyValuePairs[i].split("=");
            result.append(parts[0]).append("-").append(parts[1]);
            if (i < keyValuePairs.length - 1) {
                result.append("，");
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        Object mapObject1 = "{洪泽=1.905}";
        Object mapObject2 = "{宿迁本部=3.223, 邳州=3.223, 淮阴=3.223}";
        Object mapObject3 = "{}";

        String result1 = processMapObject(mapObject1);
        String result2 = processMapObject(mapObject2);
        String result3 = processMapObject(mapObject3);

        System.out.println(result1);
        System.out.println(result2);
        System.out.println("处理空映射结果: " + result3);
    }
}